<script>
import Popconfirm from '@/components/Popconfirm/popconfirm.vue'
import { deleteRoom } from '@/api/dorm'
export default {
  components: {
    Popconfirm
  },
  props: {
    roomId: {
      type: Number
    }
  },
  methods: {
    sleep(t) {
      return new Promise(r => setTimeout(r, t))
    },
    async deleteApartment() {
      if (typeof this.roomId !== 'number') return
      await this.sleep(300)
      return await deleteRoom(this.roomId)
    },
    handleDeleteFailed(e) {
      this.$message.error(e?.message ?? '删除失败！')
    },
    handleDeleteSuccess(e) {
      console.log(e)
      this.$message.success(e?.message ?? '删除成功')
      this.$emit('success', e)
    }
  }
}
</script>

<template>
  <Popconfirm
    :confirm-fn="deleteApartment"
    @success="handleDeleteSuccess"
    @fail="handleDeleteFailed"
  />
</template>
